<?php

/**
 *
 * @author Kevin_ren  <330202207@qq.com>
 */

namespace Common\Model;

class AdminModel extends CommonModel
{
    protected $pk        = 'admin_id';
    protected $tableName = 'admin';
    
    public function getAdminByUsername($username)
    {
        $data = $this->find(array('where' => array('username' => $username, 'closed' => 0)));
        return $this->_format($data);
    }
    
    public  function _format($data)
    {
        $roles = array_column(D('Role')->getAllData(), null,'id');;
        if(!empty($data)) {
            $data['role_name'] = $roles[$data['role_id']]['role_name'];
        }
        return $data;
    }
}